package com.example.myapplication02;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class CheckBoxActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener{
    TextView hobby;
    CheckBox shuttlecock;
    CheckBox basketball;
    CheckBox pingpong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_check_box);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        shuttlecock=findViewById(R.id.shuttlecock);
        basketball=findViewById(R.id.basketball);
        pingpong=findViewById(R.id.pingpong);
        shuttlecock.setOnCheckedChangeListener(this);
        basketball.setOnCheckedChangeListener(this);
        pingpong.setOnCheckedChangeListener(this);
        hobby = findViewById(R.id.textView3);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        String montion=compoundButton.getText().toString();
        if(b){
            hobby.setText("你的爱好是"+montion);
        }else  {
            hobby.setText("你取消了爱好"+montion);
        }
    }
}